<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>亚马逊 - 产品显示</title>
    <link href="${pageContext.request.contextPath}/css/index.css"
          rel="stylesheet" type="text/css"/>
    <link href="${pageContext.request.contextPath}/css/adv.css"
          rel="stylesheet" type="text/css"/>
    <link href="${pageContext.request.contextPath}/css/style.css"
          rel="stylesheet" type="text/css"/>
    <script src="${pageContext.request.contextPath}/scripts/jquery-2.1.0.js"
            type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/scripts/adv.js"
            type="text/javascript"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/scripts/function.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/scripts/index.js"></script>
    <script type="text/javascript" src="scripts/product_view.js"></script>
    <script>
        $(function () {
            $("#add").click(function () {
                var t = $("#count");
                t.val(parseInt(t.val()) + 1);
            })
            $("#minus").click(function () {
                var t = $("#count");
                t.val(parseInt(t.val()) - 1)
                if (parseInt(t.val()) < 1) {
                    t.val(1);
                }
                if (parseInt(t.val()) >= $("#stock").html()) {
                    t.val($("#stock").html());
                }
            })
            shopping();
            AddInShopCart();
        })

        //
        // var $t=parseInt($("#count").val()+1);
        // // t.val(parseInt(t.val())+1);
        // if($t >= $("#stock").html()){
        // 	$t = $("#stock").html();
        // }
        // $("#minus").click(function() {
        //     var $t = $("#count");
        //     t.val(parseInt(t.val()) - 1)
        //     if (parseInt(t.val()) < 1) {
        //         t = 1;
        //     }
        //
        // })
        function shopping() {
            $("#GoInshop").click(function () {
                $.post("${pageContext.request.contextPath}/shopCarts?param=addShopItem", {
                    "count": $("#count").val()
                }, function (data) {
                    window.location="${pageContext.request.contextPath}/product?param=shopCarItem";
                }, "json");
            })
        }


        function AddInShopCart() {
            $("#addCart").click(function () {
                alert(666)
                $.post("${pageContext.request.contextPath}/shopCarts?param=addShopItem", {
                        "count": $("#count").val()
                    },function (data) {
                    alert(2)
                    if(data.success!=true){
                        alert(data.info)

                    }else{
                        alert(4)
                        window.location="${pageContext.request.contextPath}/product?param=shopCarItem";
                    }
                    }, "json");
            })
        }


    </script>
</head>
<body>
<%@ include file="index_top.jsp" %>
<div id="position" class="wrap">
    您现在的位置：<a href="${pageContext.request.contextPath}/news?param=showall&id=${sessionScope.pro.id}">亚马逊</a> &gt;<a
        href="${pageContext.request.contextPath}/product-list.jsp">${requestScope.thir.name}</a> &gt; <a
        href="">${requestScope.firt.name}</a>
</div>
<div id="main" class="wrap">
    <div class="lefter">
        <%@ include file="index_product_sort.jsp" %>
    </div>
    <div id="product" class="main">
        <h1>商品名称:${requestScope.pro.name}</h1>
        <div class="infos">
            <div class="thumb">
                <img style="width: 100px; height: 100px;" src="${sessionScope.pro.img_source}"/>
            </div>
            <div class="buy">
                <p>
                    商城价：<span class="price">￥${sessionScope.pro.price}</span>
                </p>
                <c:choose>
                    <c:when test="${sessionScope.NOHA.stock>0}">
                        <p>
                            <span id="stock">库 存：${sessionScope.NOHA.stock} </span><input type="button" id="minus"
                                                                                          value=" - " width="3px">
                            <input type="text" id="count" name="count" value="1" maxlength="5"
                                   size="1" style="text-align: center; vertical-align: middle">
                            <input type="button" id="add" value=" + " width="2px">

                        <div class="button">

                            <a href="${pageContext.request.contextPath}/product?param=shopCarItem">
                                <input type="button" name="button" value="" style="background: url(images/buyNow.png)"
                                       id="GoInshop"/>
                            </a>
                            <a href="#">
                                <input type="button" name="imageField" src="images/cartbutton.png" id="addCart"/>
                            </a>
                        </div>
                        </p>
                    </c:when>

                    <c:otherwise>
                        <p>
                            库 存：<span id="stoc"></span>(无货)
                        </p>
                    </c:otherwise>
                </c:choose>
                <%--<div class="button">
                    <input type="button" name="button" value=""
                        style="background: url(images/buyNow.png)" /> <input
                        type="image" name="imageField" src="images/cartbutton.png"/>
                </div>--%>
            </div>
            <div class="clear"></div>
        </div>
        <div class="introduce">
            <h2>
                <strong>商品详情</strong>
            </h2>
            <div class="text">
                商品名字：${sessionScope.pro.name}<br/> 商品描述：${sessionScope.pro.description}<br/>
                商品价格：￥${sessionScope.pro.price}<br/> 商品库存：${sessionScope.pro.stock}<br/>
            </div>
        </div>
    </div>
    <div class="clear"></div>
</div>
<div id="footer">Copyright &copy; 2018 上海海文 All Rights Reserved.
</div>
</body>
</html>

